import tkinter
import threading
import time
import numpy as np
import cv2
import pyautogui
from pyscreeze import ImageNotFoundException

# 数据
# 牌     空  A  2  3  4  5  6  7  8  9  10 J  Q  K  小 大
cards = [0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1]
myConfidence = 0.9  # 我的牌的置信度max=1
otherConfidence = 0.95  # 别人的牌的置信度
whiteConfidence = 0.97  # 检测白块的置信度
myFilter = 19  # 两牌之间的距离。小于此值视为同一张牌。我的牌。
otherFilter = 15  # 单位像素。别人的牌检测结果过滤参数
sleepTime = 1.5  # 左右截完图后睡眠时间s.2有点长,1短受炸弹影响

# 坐标格式：(left, top, width, height)
myPos = (300, 780, 1300, 100)  # 我的截图区域
lPos = (430, 420, 520, 120)  # 左边截图区域
rPos = (980, 420, 520, 120)  # 右边截图区域

# 信号值
shouldExit = 0  # 结束
is_recording = False# 标记记牌子线程状态变量
canRecordLock = threading.Lock()  # 创建(全局)锁
# .acquire()到.release()之间的代码，同一时间只能被一个线程'写'

# 轮数变量
recordLeft = {'rdw': 0,
              'bxw': 0,
              'b2': 0,
              'r2': 0,
              'bA': 0,
              'rA': 0,
              'bK': 0,
              'rK': 0,
              'bQ': 0,
              'rQ': 0,
              'bJ': 0,
              'rJ': 0,
              'b10': 0,
              'r10': 0,
              'b9': 0,
              'r9': 0,
              'b8': 0,
              'r8': 0,
              'b7': 0,
              'r7': 0,
              'b6': 0,
              'r6': 0,
              'b5': 0,
              'r5': 0,
              'b4': 0,
              'r4': 0,
              'b3': 0,
              'r3': 0,
              }  # 上次记录
recordRight = {'rdw': 0,
               'bxw': 0,
               'b2': 0,
               'r2': 0,
               'bA': 0,
               'rA': 0,
               'bK': 0,
               'rK': 0,
               'bQ': 0,
               'rQ': 0,
               'bJ': 0,
               'rJ': 0,
               'b10': 0,
               'r10': 0,
               'b9': 0,
               'r9': 0,
               'b8': 0,
               'r8': 0,
               'b7': 0,
               'r7': 0,
               'b6': 0,
               'r6': 0,
               'b5': 0,
               'r5': 0,
               'b4': 0,
               'r4': 0,
               'b3': 0,
               'r3': 0,
               }
# 历史出牌记录（最新的在最后）
historyLeft = [recordLeft.copy(), recordRight.copy()]
historyRight = [recordLeft.copy(), recordRight.copy()]
MAX_history = 5  # 最大历史记录数

# 创建主窗口（根容器）
root = tkinter.Tk()
root.wm_attributes('-topmost', 1)  # 1置顶窗口。0恢复正常
root.title('T')  # 设置窗口标题
root.geometry('550x120')  # 宽度x高度+X坐标+Y坐标 单位像素，左上角开始
root.resizable(0, 0)  # 用户不可调宽,高
# 按钮当做状态指示灯
lamp = tkinter.Button(root, text=' ', width=3, height=1)  # 按钮，直接放在root上，不用frame
lamp.place(x=510, y=10)  # 相对坐标(相对父容器)
# 布局管理器：place精准。pack自动设位置大小
lamp.config(background='yellow')  # 黄色
# 黄灯：已结束记牌线程。 红灯：要开始截图。 绿灯：已更新界面

# 界面变量
# 可变字符，接收下拉菜单选中值
leftmeuVal = tkinter.StringVar(value='L')
rightmeuVal = tkinter.StringVar(value='R')
# alphaInEntry = tkinter.StringVar(value="1")  # 用于透明度
num_dw = tkinter.StringVar()  # 大王
num_xw = tkinter.StringVar()  # 小王
num_2 = tkinter.StringVar()  # 2
num_A = tkinter.StringVar()  # A
num_K = tkinter.StringVar()  # K
num_Q = tkinter.StringVar()  # Q
num_J = tkinter.StringVar()  # J
num_10 = tkinter.StringVar()  # 10
num_9 = tkinter.StringVar()  # 9
num_8 = tkinter.StringVar()  # 8
num_7 = tkinter.StringVar()  # 7
num_6 = tkinter.StringVar()  # 6
num_5 = tkinter.StringVar()  # 5
num_4 = tkinter.StringVar()  # 4
num_3 = tkinter.StringVar()  # 3


# 更新界面变量/牌数/下拉菜单。绿灯
def loadCardsNum():  # 显示牌的数目
    global cards, num_dw, num_xw, num_2, num_A, num_K, num_Q, num_J, num_10, num_9, num_8, num_7, num_6, num_5
    global num_4, num_3
    global lamp,canRecordLock

    # 牌数cards转为字符串strCards
    strCards = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
    # 牌         空  A   2   3   4   5   6   7   8   9   10  J   Q   K   小   大
    canRecordLock.acquire()#读总牌数cards
    for i in range(16):
        if cards[i] == 0:
            strCards[i] = ''
        else:
            strCards[i] = str(cards[i])
    canRecordLock.release()
    # StringVar.set将变量更新事件添加到(主线程的)'事件队列'
    num_dw.set(strCards[15])
    num_xw.set(strCards[14])
    num_2.set(strCards[2])
    num_A.set(strCards[1])
    num_K.set(strCards[13])
    num_Q.set(strCards[12])
    num_J.set(strCards[11])
    num_10.set(strCards[10])
    num_9.set(strCards[9])
    num_8.set(strCards[8])
    num_7.set(strCards[7])
    num_6.set(strCards[6])
    num_5.set(strCards[5])
    num_4.set(strCards[4])
    num_3.set(strCards[3])

    # 更新下拉菜单
    update_left_menu()#内部委托主程序
    update_right_menu()#内部委托主程序
    # 让主线程在空闲时更新灯
    root.after(0, lambda: lamp.config(background='springgreen'))


# 设置透明度
# root.attributes('-alpha', 0.5)#设置窗口透明度0-1
# def setAlpha():
#     global alphaInEntry
#     root.attributes('-alpha', float(alphaInEntry.get()))  # 字符转浮点数


# 在图片上绘制三个矩形区域（myPos、lPos、rPos）
def NowPosArea():
    # 1.用指定图片
    # img_Path_00 = "./pics/00.png"
    # img = cv2.imread(img_Path_00)#指定文件
    # 2.截图
    screenshot = pyautogui.screenshot()  # 返回PIL Image对象
    img = np.array(screenshot)  # 转换为numpy数组（RGB格式）
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)  # RGB->BGR（OpenCV默认）

    # 定义三个矩形的颜色（BGR格式）和线宽
    colors = [
        (0, 0, 255),  # 红色：myPos
        (0, 255, 0),  # 绿色：lPos
        (255, 0, 0)  # 蓝色：rPos
    ]
    thickness = 2  # 线宽

    # 转换位置：将 (left, top, width, height) 转换为 (左上角, 右下角)
    for pos, color in zip([myPos, lPos, rPos], colors):
        left, top, width, height = pos
        # 计算右下角坐标：left + width, top + height
        right = left + width
        bottom = top + height
        # 绘制矩形
        cv2.rectangle(img, (left, top), (right, bottom), color, thickness)

    # 创建可调整大小的窗口
    cv2.namedWindow('Pos', cv2.WINDOW_NORMAL)  # 默认cv2.WINDOW_AUTOSIZE大小固定
    # 显示图片并等待按键关闭
    cv2.imshow('Pos', img)
    cv2.waitKey(0)  # 任意按键关闭窗口
    cv2.destroyAllWindows()


# 结束记牌线程，黄灯
def stop():
    global shouldExit, lamp
    shouldExit = 0  # 停止
    root.after(0, lambda: lamp.config(background='yellow'))


# 启动记牌线程startRecord
def start():
    global is_recording,shouldExit, cards, recordRight, recordLeft, historyRight, historyLeft
    if is_recording:  # 若已有线程在运行，直接返回
        return
    is_recording = True
    shouldExit = 1  # 开始
    cards = [0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1]  # 重置牌总数
    # 重置历史记录
    recordLeft = {'rdw': 0,
                  'bxw': 0,
                  'b2': 0,
                  'r2': 0,
                  'bA': 0,
                  'rA': 0,
                  'bK': 0,
                  'rK': 0,
                  'bQ': 0,
                  'rQ': 0,
                  'bJ': 0,
                  'rJ': 0,
                  'b10': 0,
                  'r10': 0,
                  'b9': 0,
                  'r9': 0,
                  'b8': 0,
                  'r8': 0,
                  'b7': 0,
                  'r7': 0,
                  'b6': 0,
                  'r6': 0,
                  'b5': 0,
                  'r5': 0,
                  'b4': 0,
                  'r4': 0,
                  'b3': 0,
                  'r3': 0,
                  }  # 上次记录
    recordRight = {'rdw': 0,
                   'bxw': 0,
                   'b2': 0,
                   'r2': 0,
                   'bA': 0,
                   'rA': 0,
                   'bK': 0,
                   'rK': 0,
                   'bQ': 0,
                   'rQ': 0,
                   'bJ': 0,
                   'rJ': 0,
                   'b10': 0,
                   'r10': 0,
                   'b9': 0,
                   'r9': 0,
                   'b8': 0,
                   'r8': 0,
                   'b7': 0,
                   'r7': 0,
                   'b6': 0,
                   'r6': 0,
                   'b5': 0,
                   'r5': 0,
                   'b4': 0,
                   'r4': 0,
                   'b3': 0,
                   'r3': 0,
                   }
    historyLeft = [recordLeft.copy(), recordRight.copy()]  # 历史记录
    historyRight = [recordLeft.copy(), recordRight.copy()]
    t = threading.Thread(target=startRecord)  # target='要调用的函数名'
    t.daemon = True  # 设为守护线程，当主程序(窗口)退出时线程终止
    t.start()  # 启动线程


# 记牌子线程
def startRecord():  # 开始记牌
    global is_recording,shouldExit,recordRight, recordLeft, historyRight, historyLeft
    findMyCards()  # 总数-我手牌
    loadCardsNum()  # 对我截图后,更新界面变量/牌数/下拉菜单。绿灯
    # 一直监测左右
    while shouldExit:
        # 处理右边玩家
        nowRightCards = findOtherCards(rPos)  # 现在截图
        if nowRightCards != recordRight:  # 不同
            canRecordLock.acquire()  # 获得锁
            ChangeAllCards(nowRightCards)  # 变总牌
            # 保存上次记录
            historyRight.append(recordRight.copy())
            # 保持最多5条记录
            if len(historyRight) > MAX_history:
                historyRight.pop(0)
            canRecordLock.release()  # 释放锁
            recordRight = nowRightCards.copy()# 更新记录
        # 处理左边玩家
        nowLeftCards = findOtherCards(lPos)  # 截图
        if nowLeftCards != recordLeft:  # 不同
            canRecordLock.acquire()  # 获得锁
            ChangeAllCards(nowLeftCards)  # 变总牌
            # 保存上次记录
            historyLeft.append(recordLeft.copy())
            # 保持最多5条记录
            if len(historyLeft) > MAX_history:
                historyLeft.pop(0)
            canRecordLock.release()  # 释放锁
            recordLeft = nowLeftCards.copy()# 更新记录

        loadCardsNum()  # 左右截图后,更新界面变量/牌数/下拉菜单
        time.sleep(sleepTime)
    is_recording = False  # 线程结束后标记为未运行

# 去除重复的匹配结果，返回数值
def cardsFilter(location, distance):  # 牌检测结果滤波
    if len(location) == 0:
        return 0
    locList = [location[0][0]]  # 第一个元组的Left值。
    # [(left, top, width, height), (left...
    count = 1
    for e in location:  # 对每一个元组
        flag = 1  # “是新的”标志
        for have in locList:
            if abs(e[0] - have) <= distance:  # 很近
                flag = 0  # 重复
                break  # 结束for have循环，后面没必要比较了
        if flag:
            count += 1
            locList.append(e[0])
    return count


# 总数-我手牌。红灯后截图，更新界面变量变绿灯
def findMyCards():
    global cards, lamp
    myCardsNum = {'rdw': 0,
                  'bxw': 0,
                  'b2': 0,
                  'r2': 0,
                  'bA': 0,
                  'rA': 0,
                  'bK': 0,
                  'rK': 0,
                  'bQ': 0,
                  'rQ': 0,
                  'bJ': 0,
                  'rJ': 0,
                  'b10': 0,
                  'r10': 0,
                  'b9': 0,
                  'r9': 0,
                  'b8': 0,
                  'r8': 0,
                  'b7': 0,
                  'r7': 0,
                  'b6': 0,
                  'r6': 0,
                  'b5': 0,
                  'r5': 0,
                  'b4': 0,
                  'r4': 0,
                  'b3': 0,
                  'r3': 0,
                  }
    root.after(0, lambda: lamp.config(background='red'))#让主线程变灯
    img = pyautogui.screenshot(region=myPos)  # 对我手牌截图
    # 对我手牌计数
    for i in myCardsNum.keys():
        try:
            result = pyautogui.locateAll(needleImage='pics/m' + i + '.png',
                                         haystackImage=img, grayscale=False,
                                         confidence=myConfidence)  # 默认grayscale=True灰度模式
            # needleImage(小图)要找的目标。从haystackImage(大图)找。
            # result是生成器对象，生成的是许多个 (left, top, width, height)
            myCardsNum[i] = cardsFilter(list(result), myFilter)  # 去重后结果的个数
        except ImageNotFoundException:
            continue  # 继续处理下一张卡牌
    # 总数=总数-我手牌
    # cards[1] = cards[1] - (myCardsNum['bA'] + myCardsNum['rA'])
    cards[1] -= myCardsNum['bA'] + myCardsNum['rA']
    cards[2] -= myCardsNum['b2'] + myCardsNum['r2']
    cards[3] -= myCardsNum['b3'] + myCardsNum['r3']
    cards[4] -= myCardsNum['b4'] + myCardsNum['r4']
    cards[5] -= myCardsNum['b5'] + myCardsNum['r5']
    cards[6] -= myCardsNum['b6'] + myCardsNum['r6']
    cards[7] -= myCardsNum['b7'] + myCardsNum['r7']
    cards[8] -= myCardsNum['b8'] + myCardsNum['r8']
    cards[9] -= myCardsNum['b9'] + myCardsNum['r9']
    cards[10] -= myCardsNum['b10'] + myCardsNum['r10']
    cards[11] -= myCardsNum['bJ'] + myCardsNum['rJ']
    cards[12] -= myCardsNum['bQ'] + myCardsNum['rQ']
    cards[13] -= myCardsNum['bK'] + myCardsNum['rK']
    cards[14] -= myCardsNum['bxw']
    cards[15] -= myCardsNum['rdw']


# 找、输出别人手牌。红灯后截图
def findOtherCards(pos):
    global lamp
    root.after(0, lambda: lamp.config(background='red'))#让主线程变灯
    otherCardsNum = {'rdw': 0,
                     'bxw': 0,
                     'b2': 0,
                     'r2': 0,
                     'bA': 0,
                     'rA': 0,
                     'bK': 0,
                     'rK': 0,
                     'bQ': 0,
                     'rQ': 0,
                     'bJ': 0,
                     'rJ': 0,
                     'b10': 0,
                     'r10': 0,
                     'b9': 0,
                     'r9': 0,
                     'b8': 0,
                     'r8': 0,
                     'b7': 0,
                     'r7': 0,
                     'b6': 0,
                     'r6': 0,
                     'b5': 0,
                     'r5': 0,
                     'b4': 0,
                     'r4': 0,
                     'b3': 0,
                     'r3': 0,
                     }
    img = pyautogui.screenshot(region=pos)  # 对别人牌截图
    for i in otherCardsNum.keys():
        try:
            result = pyautogui.locateAll(needleImage='pics/o' + i + '.png',
                                         haystackImage=img, grayscale=False,
                                         confidence=otherConfidence)  # 默认grayscale=True灰度模式
            otherCardsNum[i] = cardsFilter(list(result), otherFilter)
        except ImageNotFoundException:
            continue  # 继续处理下一张卡牌
    return otherCardsNum


# 总数=总数-别人手牌。
def ChangeAllCards(otherCardsNum):
    global cards
    cards[1] -= otherCardsNum['bA'] + otherCardsNum['rA']
    cards[2] -= otherCardsNum['b2'] + otherCardsNum['r2']
    cards[3] -= otherCardsNum['b3'] + otherCardsNum['r3']
    cards[4] -= otherCardsNum['b4'] + otherCardsNum['r4']
    cards[5] -= otherCardsNum['b5'] + otherCardsNum['r5']
    cards[6] -= otherCardsNum['b6'] + otherCardsNum['r6']
    cards[7] -= otherCardsNum['b7'] + otherCardsNum['r7']
    cards[8] -= otherCardsNum['b8'] + otherCardsNum['r8']
    cards[9] -= otherCardsNum['b9'] + otherCardsNum['r9']
    cards[10] -= otherCardsNum['b10'] + otherCardsNum['r10']
    cards[11] -= otherCardsNum['bJ'] + otherCardsNum['rJ']
    cards[12] -= otherCardsNum['bQ'] + otherCardsNum['rQ']
    cards[13] -= otherCardsNum['bK'] + otherCardsNum['rK']
    cards[14] -= otherCardsNum['bxw']
    cards[15] -= otherCardsNum['rdw']


# (反向操作)总数=总数+别人手牌。
def BackChangeAllCards(otherCardsNum):
    global cards
    cards[1] += otherCardsNum['bA'] + otherCardsNum['rA']
    cards[2] += otherCardsNum['b2'] + otherCardsNum['r2']
    cards[3] += otherCardsNum['b3'] + otherCardsNum['r3']
    cards[4] += otherCardsNum['b4'] + otherCardsNum['r4']
    cards[5] += otherCardsNum['b5'] + otherCardsNum['r5']
    cards[6] += otherCardsNum['b6'] + otherCardsNum['r6']
    cards[7] += otherCardsNum['b7'] + otherCardsNum['r7']
    cards[8] += otherCardsNum['b8'] + otherCardsNum['r8']
    cards[9] += otherCardsNum['b9'] + otherCardsNum['r9']
    cards[10] += otherCardsNum['b10'] + otherCardsNum['r10']
    cards[11] += otherCardsNum['bJ'] + otherCardsNum['rJ']
    cards[12] += otherCardsNum['bQ'] + otherCardsNum['rQ']
    cards[13] += otherCardsNum['bK'] + otherCardsNum['rK']
    cards[14] += otherCardsNum['bxw']
    cards[15] += otherCardsNum['rdw']


# 返回字符串，'0:没出'
def format_record(index, record):
    # 筛选出值不为0的牌
    non_zero_items = [(key, value) for key, value in record.items() if value != 0]
    # 都是0,返回'没出'
    if not non_zero_items:
        return f'{index}:没出'

    items_str = []  # 要返回的内容
    # 拼接key和value
    chars_to_remove = ['o','b','r']  # 要删除的字符
    for key, value in non_zero_items:
        processed_key = key
        for char in chars_to_remove:
            processed_key = processed_key.replace(char, '')
        items_str.extend([processed_key] * value)

    return f"{index}:{items_str}"


# 更新左下拉菜单.清空、添加选项、绑定函数
def update_left_menu():
    def update():# 委托主线程执行更新
        # 清空现有选项
        inmenu = leftdownMeu['menu']  # 获取downMeu的“内部容器menu对象”
        inmenu.delete(0, 'end')  # 清空选项。从第1个到'最后'个
        # 添加新选项
        canRecordLock.acquire()
        try:
            for i, record in enumerate(historyLeft):
                clab = format_record(i, record)  # 格式化后文本
                # 绑定事件，clab标签对应的序号i作为返回值赋给leftmeuVal
                inmenu.add_command(label=clab, command=lambda v=i: leftmeuVal.set(v))
        finally:
            canRecordLock.release()
    root.after(0, update)# 委托主线程执行更新



# 更新右下拉菜单.清空、添加选项、绑定函数
def update_right_menu():
    def update():  # 委托主线程执行更新
        # 清空现有选项
        inmenu = rightdownMeu['menu']  # 获取downMeu的“内部容器menu对象”
        inmenu.delete(0, 'end')  # 清空选项。从第1个到'最后'个
        # 添加新选项
        canRecordLock.acquire()
        try:
            for i, record in enumerate(historyRight):
                clab = format_record(i, record)  # 格式化后文本
                # 绑定事件，clab标签对应的序号i作为返回值赋给leftmeuVal
                inmenu.add_command(label=clab, command=lambda v=i: rightmeuVal.set(v))
        finally:
            canRecordLock.release()
    root.after(0, update)# 委托主线程执行更新


# 左边回退、删除选中的历史记录.更新左下拉菜单
def ReSetLeft():
    global historyLeft
    canRecordLock.acquire()
    try:# 容错： leftmeuVal默认'L'
        # 容错：空记录退出函数
        if not historyLeft:
            return# finally释放锁
        # 获取选中的索引
        idx = int(leftmeuVal.get())  # 字符转int
        # 容错：索引是否有效
        if idx < 0 or idx >= len(historyLeft):
            return# finally释放锁
        # 获取目标历史记录并删除
        idxRecord = historyLeft.pop(idx)  # 删除同时返回值
        # 回退卡牌数量
        BackChangeAllCards(idxRecord)
    except ValueError:# 容错： leftmeuVal默认'L'
        return
    finally:  # 无论是否发生异常，均释放锁
            canRecordLock.release()
    loadCardsNum()  # 左退完,更新界面变量/牌数/下拉菜单


# 右边回退、删除选中的历史记录.更新右下拉菜单
def ReSetRight():
    global historyRight
    canRecordLock.acquire()
    try:  # 容错：rightmeuVal默认'R'
        # 容错：空记录退出函数
        if not historyRight:
            return# finally释放锁
        # 获取选中的索引
        idx = int(rightmeuVal.get())  # 字符转int
        # 容错：索引是否有效
        if idx < 0 or idx >= len(historyRight):
            return# finally释放锁
        # 获取目标历史记录并删除
        idxRecord = historyRight.pop(idx)  # 删除同时返回值
        # 回退卡牌数量、更新所有界面
        BackChangeAllCards(idxRecord)
    except ValueError:  # 容错：rightmeuVal默认'R'
        return
    finally:  # 无论是否发生异常，均释放锁
        canRecordLock.release()
    loadCardsNum()  # 右退完,更新界面变量/牌数/下拉菜单


# 以下的代码块只有在GUI被直接运行时才会执行，作为包被调用时不执行
if __name__ == '__main__':
    # 主内容：标签和输入框（一排排列）
    x_start = 10  # 起始X坐标
    y_label = 10  # 标签Y坐标（上方）
    y_entry = 40  # 输入框Y坐标（下方）
    x_add = 32  # 每个元素的X间距

    # 牌标签和输入框对应关系
    label_vars = [
        ('大', num_dw), ('小', num_xw), ('2', num_2), ('A', num_A), ('K', num_K),
        ('Q', num_Q), ('J', num_J), ('10', num_10), ('9', num_9), ('8', num_8),
        ('7', num_7), ('6', num_6), ('5', num_5), ('4', num_4), ('3', num_3)
    ]

    # 循环创建标签和输入框
    for label_text, var in label_vars:
        tkinter.Label(root, text=label_text, font=('', 12), width=2).place(x=x_start, y=y_label)
        tkinter.Entry(root, textvariable=var, font=('', 12), width=2).place(x=x_start, y=y_entry)
        x_start += x_add  # 移动到下一个位置

    # 功能按钮
    w_bt = 5  # 按钮宽度. 5个当前字符宽度.(默认12号字)
    x_it = 70  # 按钮之间的水平间距（包含按钮宽度）
    x_st = 10  # 起始X坐标
    tkinter.Button(root, text='stop', command=lambda: threading.Thread(target=stop(), daemon=True).start()
                   , width=w_bt).place(x=x_st, y=70)
    tkinter.Button(root, text='Pos', command=lambda: threading.Thread(target=NowPosArea(), daemon=True).start(),
                   width=w_bt).place(x=x_st + x_it, y=70)
    tkinter.Button(root, text='开始', command=start, width=w_bt).place(x=x_st + x_it * 2, y=70)
    tkinter.Button(root, text='左退',
                   command=lambda: threading.Thread(target=ReSetLeft, daemon=True).start(),
                   width=w_bt).place(x=x_st + x_it * 3, y=70)
    tkinter.Button(root, text='右退',
                   command=lambda: threading.Thread(target=ReSetRight, daemon=True).start(),
                   width=w_bt).place(x=x_st + x_it * 5, y=70)
    # 创建下拉菜单对象
    leftdownMeu = tkinter.OptionMenu(root, leftmeuVal, '0')
    leftdownMeu.place(x=x_st + x_it * 4, y=70)
    rightdownMeu = tkinter.OptionMenu(root, rightmeuVal, '1')
    rightdownMeu.place(x=x_st + x_it * 6, y=70)

    # tkinter.Entry(root, textvariable=alphaInEntry, width=4).place(x=220, y=72)
    # tkinter.Button(root, text='设透明', command=setAlpha, width=5).place(x=260, y=70)
    # 窗口开始
    root.mainloop()
